package com.michael.staticproxy.datasouce;

import java.text.SimpleDateFormat;
import java.util.Date;

public class SimpleProxy {

    private IProductService iProductService;

    public SimpleProxy(IProductService iProductService){
        this.iProductService = iProductService;
    }

    public int createProduct(Product product){
        before();
        int cnt = iProductService.insert(product);

        after();
        return cnt;
    }

    private void after() {
        DynamicDataSourceEntity.restore();
    }

    private void before() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        DynamicDataSourceEntity.setLocal(sdf.format(new Date()));
    }


}
